package com.example.atv;

import androidx.activity.result.ActivityResultLauncher;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.List;

public class MainActivity2 extends BaseActivity {

    Button btn1,btn2;
    EditText edt1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);



        btn1 = findViewById(R.id.atv2_btn1);
        btn2 = findViewById(R.id.atv2_btn2);
        edt1 = findViewById(R.id.atv2_edt1);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(MainActivity2.this,MainActivity.class);
//                startActivity(intent);

                // 在SecondActivity中
                Intent resultIntent = new Intent();
                resultIntent.putExtra("result_key", "返回数据");
                setResult(RESULT_OK, resultIntent); // RESULT_OK表示操作成功，也可以使用RESULT_CANCELED表示取消或失败
                finish();
            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = getIntent();
                String name = intent.getStringExtra("name");
                edt1.setText(name);


            }
        });

    }


    /**
     * 返回按钮时调用
     */
    @Override
    public void onBackPressed() {
        super.onBackPressed();

        Intent intent = new Intent();
        intent.putExtra("result_key", "Hello FirstActivity");
        setResult(RESULT_OK, intent);
        finish();
    }
}